package edu.mobbuzz.page.menu;

import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Container;
import com.sun.lwuit.Display;
import com.sun.lwuit.Font;
import com.sun.lwuit.Form;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import edu.mobbuzz.util.string.MenuString;
import edu.mobbuzz.util.theme.Theme;
import java.io.IOException;

public class OutboxMenu extends Menu {
    private Form outboxMenuForm;
    private Container outboxMenuPanel; 
    
    private Label menuTitle;
    private Label menuIconLabel;
    private Label menuDescription;
    private Image menuIcon;   
    
    public OutboxMenu(){
        outboxMenuForm = new Form(){
            public void keyPressed(int keyCode) {
                gameActionPerformed(keyCode);
            }        
        };             
        outboxMenuPanel = new Container();
        
        menuTitle = new Label(getMenuTitle());
        menuDescription = new Label();
        try {
            menuIcon = Image.createImage("/icons/outbox.gif"); //Theme.getResources().getImage("outbox.png");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        menuIconLabel = new Label(menuIcon); 
    }
    public void showPage(){ 
        menuIconLabel.setAlignment(Component.CENTER);
        menuIconLabel.getStyle().setMargin(50, 0, 0, 0);
        menuIconLabel.getStyle().setBgTransparency(0);  
        
        menuTitle.setAlignment(Component.LEFT);
        menuTitle.getStyle().setMargin(5, 0, 5, 0);
        menuTitle.getStyle().setFont(Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL));
        menuTitle.getStyle().setBgTransparency(0);   
         
        menuDescription.setText("Your shared RSS");      
        menuDescription.setAlignment(Component.LEFT);
        menuDescription.getStyle().setFont(Theme.getFontDescriptionStyle("SansSerif"));
        menuDescription.getStyle().setMargin(5, 0, 5, 0);         
        menuDescription.getStyle().setBgTransparency(0); 
        
               
        outboxMenuPanel.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        //outboxMenuPanel.getStyle().setBgImage(Theme.getBackground());
        outboxMenuPanel.addComponent(menuIconLabel);
        outboxMenuPanel.addComponent(menuTitle);
        
        outboxMenuPanel.addComponent(menuDescription);
        outboxMenuForm.setLayout(new BorderLayout()); 
        outboxMenuForm.addComponent(BorderLayout.CENTER, outboxMenuPanel);        
        outboxMenuForm.addCommand(getExitCmd());
        outboxMenuForm.addCommand(getOnlineCmd());
        outboxMenuForm.addCommand(new Command("Open") {
            public void actionPerformed(ActionEvent evt) {
               //
            }
        }); 
                 
        outboxMenuForm.setCommandListener(getActionlistener());
        outboxMenuForm.show();
    }

    public String getMenuTitle() {
        return MenuString.OUTBOX;
    }

    public void actionPerformed(ActionEvent ev) {
        if(ev.getCommand().getCommandName().equals(">>")){
           //
        }
    }
    
    public void gameActionPerformed(int keyCode){
        int game = Display.getInstance().getGameAction(keyCode);
        if(game == Display.GAME_RIGHT){
            getOutboxTransitionRight();
        }else if(game == Display.GAME_LEFT){
            getOutboxTransitionLeft();
        }
    }
    
    public void getOutboxTransitionRight(){
        outboxMenuForm.setTransitionOutAnimator(Theme.getTransitionOut());
        CategoryMenu categoryMenu = new CategoryMenu();
        categoryMenu.setExitCmd(getExitCmd());
        categoryMenu.setActionlistener(getActionlistener());
        categoryMenu.showPage();
    }
    
    public void getOutboxTransitionLeft(){
       outboxMenuForm.setTransitionOutAnimator(Theme.getTransitionIn());
       InboxMenu inboxMenu = new InboxMenu();
       inboxMenu.setExitCmd(getExitCmd());
       inboxMenu.setActionlistener(getActionlistener());
       inboxMenu.showPage();
    }
}
